package com.czl.module_service.binding

import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.databinding.BindingAdapter
import com.czl.module_service.view.SuperRelativeLayout

/**
 * @author by xubin,
 * @date on 2022/1/18.
 * PS: Not easy to write code, please indicate.
 */
object ViewAdapter {
    @JvmStatic
    @BindingAdapter(value = ["drawableTop"], requireAll = false)
    fun setTextViewTopRes(textView: TextView, resId: Int?) {
        if (resId == null) {
            return
        }
        textView.setCompoundDrawables(
            null,
            ContextCompat.getDrawable(textView.context, resId).apply {
                this!!.setBounds(0, 0, this.intrinsicWidth, this.intrinsicHeight)
            },
            null,
            null
        )
    }

    @JvmStatic
    @BindingAdapter(value = ["backGroundRes"], requireAll = false)
    fun setTextViewBackGroundRes(textView: TextView, resId: Int?) {
        if (resId == null) {
            return
        }
        textView.setBackgroundResource(resId)
    }

    @JvmStatic
    @BindingAdapter(value = ["sRightTextString"], requireAll = false)
    fun setRightText(layout: SuperRelativeLayout, text: String?) {
        layout.setRightText(text)
    }
}